﻿using Kaskelot.SP.Core;
using Stockholm.SOA.Kaskelot.WCF.DataContracts;
using Stockholm.SOA.Kaskelot.WCF.DataContracts.Analys;
using Stockholm.SOA.Kaskelot.WCF.ServiceContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using Stockholm.SOA.Kaskelot.WCF.FaultContracts;

namespace Kaskelot.SP.Services
{
	public class AnalysService : BaseService<IKaskelotService>
	{
		public QueryResult ExecuteQuery(Query query, Guid valId)
		{
            try
            {
                return this.channel.ExecuteQuery(query, valId);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "ExecuteQuery", ex.Detail.ServiceError, ex);
                throw;
            }
		}

		public List<Entity> GetEntities()
		{
            try
            {
                return this.channel.GetEntities();
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "GetEntities", ex.Detail.ServiceError, ex);
                throw;
            }
		}

		public List<LookupField> GetLookupInformation()
		{
            try
            {
                return this.channel.GetLookupInformation();
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "GetLookupInformation", ex.Detail.ServiceError, ex);
                throw;
            }
		}

		public List<Query> GetQueriesByPerson(string loginName)
		{
			try
			{
                return this.channel.GetQueriesByPerson(loginName);
			}
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "GetQueriesByPerson", ex.Detail.ServiceError, ex);
                throw;
            }
		}

		public void SaveQuery(Query query, string loginName)
		{
			try
			{
				this.channel.SaveQuery(query, loginName);
			}
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "SaveQuery", ex.Detail.ServiceError, ex);
                throw;
            }
		}

		public void DeleteQuery(int id)
		{
            try
            {
                this.channel.DeleteQuery(id);
            }
            catch (FaultException<ErrorInformation> ex)
            {
                Logger.LogError(this, LayerNames.Services, "DeleteQuery", ex.Detail.ServiceError, ex);
                throw;
            }
		}
	}
}
